<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Encode</title>
</head>
<body>
  <textarea id="input"></textarea>
  <div><button id="btn1">encode base64</button><button id="btn2">Decode base64</button></div>
  <textarea id="result"></textarea>

  <script>
    btn1.onclick = function () {
      result.value = 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(input.value)))
    }
    btn2.onclick = function () {
      result.value = decodeURIComponent(escape(atob(input.value.replace('data:image/svg+xml;base64,', ''))))
    }
  </script>
</body>
</html>